/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vita.vitasolution.db.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import vita.vitasolution.db.dictionaries.SolutionState;

/**
 *
 * @author harker777
 */
@Entity
@Table(name = "`SOLUTION`")
public class Solution implements Serializable, EntityWithId {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	@Size(max = 45)
	@Column(name = "Benefits")
	private String benefits;
	@Size(max = 45)
	@Column(name = "Info")
	private String info;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "PostDate")
	private Date postDate;
	@NotNull
	@Column(name = "SolutionState_ID")
	private SolutionState solutionState;
	@ManyToOne
	@JoinColumn(name = "User_ID")
	private User user;
	@ManyToOne
	@JoinColumn(name = "Case_ID")
	private Case aCase;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "solution")
	private Set<SolutionToCriteria> solutionToCriteriaSet;

	public Solution() {
		this.solutionToCriteriaSet = new HashSet<SolutionToCriteria>();
	}

	public Solution(Integer id) {
		this();
		this.setId(id);
	}

	public Solution(Integer id, String benefits, String info, Date postDate, SolutionState solutionState) {
		this(id);
		setBenefits(benefits);
		setInfo(info);
		setPostDate(postDate);
		setSolutionState(solutionState);
	}

	@Override
	public Integer getId() {
		return id;
	}

	@Override
	public void setId(Integer id) {
		this.id = id;
	}

	public String getBenefits() {
		return benefits;
	}

	public void setBenefits(String benefits) {
		this.benefits = benefits;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public Date getPostDate() {
		return postDate;
	}

	public void setPostDate(Date postDate) {
		this.postDate = postDate;
	}

	public SolutionState getSolutionState() {
		return solutionState;
	}

	public void setSolutionState(SolutionState solutionState) {
		this.solutionState = solutionState;
	}

	public User getUser() {
		return user;
	}

	public void setUserID(User user) {
		this.user = user;
	}

	public Case getCase() {
		return aCase;
	}

	public void setCase(Case aCase) {
		this.aCase = aCase;
	}

	public Set<SolutionToCriteria> getSolutionToCriteriaSet() {
		return solutionToCriteriaSet;
	}

	protected void setSolutionToCriteriaSet(Set<SolutionToCriteria> solutionToCriteriaSet) {
		this.solutionToCriteriaSet = solutionToCriteriaSet;
	}

	public void addSolutionToCriteria(SolutionToCriteria solutionToCriteria) {
		solutionToCriteria.setSolution(this);
		this.getSolutionToCriteriaSet().add(solutionToCriteria);
	}

	public void removeSolutionToCriteria(SolutionToCriteria solutionToCriteria) {
		this.getSolutionToCriteriaSet().remove(solutionToCriteria);
	}

	@Override
	public int hashCode() {
		int hash = 7;
		hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
		hash = 67 * hash + (this.benefits != null ? this.benefits.hashCode() : 0);
		hash = 67 * hash + (this.info != null ? this.info.hashCode() : 0);
		hash = 67 * hash + (this.postDate != null ? this.postDate.hashCode() : 0);
		hash = 67 * hash + (this.solutionState != null ? this.solutionState.hashCode() : 0);
		hash = 67 * hash + (this.user != null ? this.user.hashCode() : 0);
		hash = 67 * hash + (this.aCase != null ? this.aCase.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Solution other = (Solution) obj;
		if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
			return false;
		}
		if ((this.benefits == null) ? (other.benefits != null) : !this.benefits.equals(other.benefits)) {
			return false;
		}
		if ((this.info == null) ? (other.info != null) : !this.info.equals(other.info)) {
			return false;
		}
		if (this.postDate != other.postDate && (this.postDate == null || !this.postDate.equals(other.postDate))) {
			return false;
		}
		if (this.solutionState != other.solutionState) {
			return false;
		}
		if (this.user != other.user && (this.user == null || !this.user.equals(other.user))) {
			return false;
		}
		if (this.aCase != other.aCase && (this.aCase == null || !this.aCase.equals(other.aCase))) {
			return false;
		}
		return true;
	}
}
